<?php
/**
 * Created by PhpStorm.
 * User: DELL-PC
 * Date: 2018/8/2
 * Time: 10:37
 */

namespace J\Schema;

use J\Schema\Collection\ICollection;
use J\Schema\Collection\Option;
use J\Exception;

/**
 * @method int max() max($field = '*', $where = true, $model = null) 最大值
 * @method int min() min($field = '*', $where = true, $model = null) 最小值
 * @method int count() count($field = '*', $where = true, $model = null) 非空行数
 * @method int sum() sum($field = '*', $where = true, $model = null) 和
 */
interface ICurd
{
    /**
     * 增加
     *
     * @param int $id
     * @return int
     * @throws Exception
     */
    public function add($id = 0);

    /**
     * 修改
     *
     * @return int
     * @throws Exception
     */
    public function edit();

    /**
     * 删除
     *
     * @return int
     * @throws Exception
     */
    public function delete();

    /**
     * 直接删除 | 清空回收站
     *
     * @return int
     * @throws Exception
     */
    public function clear();

    /**
     * 从回收站恢复
     *
     * @return int
     * @throws Exception
     */
    public function recycle();

    /**
     * 设置查询条件为ID组
     *
     * @param int|int[] $ids
     * @return static
     * @throws Exception
     */
    public function setIds($ids = null);

    /**
     * 获取ID组
     *
     * @return int[]|int|bool
     * @throws Exception
     */
    public function getIds();

    /**
     * 设定是否可回收
     *
     * @param boolean $recyclable
     * @return static
     */
    public function setRecycle($recyclable);

    /**
     * 查询是否可回收
     *
     * @return boolean
     */
    public function isRecyclable();

    /**
     * 设置处理元素
     *
     * @param array|string $elements
     * @return static
     */
    public function setElements($elements);

    /**
     * Where
     *
     * @param IWhere|array|bool $where
     * @return static
     * @throws Exception
     */
    public function setWhere($where);

    /**
     * @return IWhere
     */
    public function getWhere();

    /**
     * Option
     *
     * @param Option $option
     * @return static
     */
    public function setOption($option);

    /**
     * @return Option
     */
    public function getOption();

    /**
     * 设置为获取原始原始数据
     * @param bool $raw
     * @return static
     */
    public function setRaw($raw);

    /**
     * 检索
     *
     * @param int $fetch_model
     * @return mixed
     * @throws Exception
     */
    public function query($fetch_model = null);

    /**
     * 查询
     *
     * @return array
     * @throws Exception
     */
    public function select();

    /**
     * 查询单行
     *
     * @return array
     * @throws Exception
     */
    public function find();

    /**
     * @return ICurd 内部表联动
     */
    public function extra();

    /**
     * @return ICurd 表级联
     * @throws Exception
     */
    public function relation();

    /**
     * @return ICollection
     */
    public function getCollection();
}